<%--
  Created by IntelliJ IDEA.
  User: 甘汝雷
  Date: 2017/5/2
  Time: 14:13
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%--解析表达式--%>
<%@ page isELIgnored="false" %>
<%--引入jstl--%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%--引入springMVC form--%>
<%@ taglib prefix="sf" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="page" uri="/xianzhiOA/pageTag" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <title>工作量分布一览</title>
    <script type="application/javascript">
        function go() {
            var workingId = document.getElementById("workingId").value;
            if (workingId != 0) {
                document.getElementById("workingForm").action = "${pageContext.request.contextPath}/Working/updateWorking.emp";
            }
        }
        function ToempShowPage() {
            window.location.href = "${pageContext.request.contextPath}/Working/selWorkingAll.emp";
        }
        function getWork() {
            var empId = ${userLogin.empId};
            var workingTime = document.getElementById("workingTime").value;
            $.ajax({
                url: '${pageContext.request.contextPath}/Working/getWork.emp',
                data: {empId: empId,workingTime: workingTime},
                type: 'post',
                dataType: 'json',
                success: function (data) {
                    document.getElementById("actual").innerHTML =data.actual;
                    document.getElementById("plan").innerHTML = data.plan;
                }
            })
        }
        function getTotal(type,f) {
            var plan = parseInt(document.getElementById("plan").innerHTML);
            var actual = parseInt(document.getElementById("actual").innerHTML);
            var planf = parseInt(document.getElementById("p"+f).value);
            var actualf = parseInt(document.getElementById("a"+f).value);
            var plan1 = 0,actual1=0;
            for (var i=0;i<4;i++){
                plan1 += parseInt(document.getElementById("p"+i).value);
                actual1 += parseInt(document.getElementById("a"+i).value);
            }
            if (type=="p") {
                if (plan1>plan){
                    document.getElementById("p"+f).focus;
                    document.getElementById("p"+f).value=0;
                    document.getElementById("plan1").innerHTML = plan1-planf;
                }else
                document.getElementById("plan1").innerHTML = plan1;
            }
            if (type=="a") {
                if (actual1>actual){
                    document.getElementById("a"+f).focus;
                    document.getElementById("a"+f).value=0;
                    document.getElementById("actual1").innerHTML = actual1-actualf;
                }else
                    document.getElementById("actual1").innerHTML = actual1;
            }
        }
    </script>
</head>
<body>
<!--头部开始-->
<jsp:include page="headerBack.jsp"></jsp:include>
<!-- 导航 -->
<jsp:include page="leftBack.jsp"></jsp:include>
<div class="main">
    <!--内容页头部-->
    <div class="page-header">
        <div class="pull-left">
            <ol class="breadcrumb visible-sm visible-md visible-lg">
                <li><a href="${pageContext.request.contextPath}/Login/goHomePage"><i class="icon fa fa-home"></i>主页</a></li>
                <li class="active"><i class="fa fa-pencil"></i>基本信息</li>
            </ol>
        </div>
        <div class="pull-right">
            <h2>主页</h2>
        </div>
    </div>
    <sf:form id="workingForm" action="${pageContext.request.contextPath}/Working/addWorking.emp" modelAttribute="working" method="post" class="search1">
        <sf:input path="workingId" type="hidden"/>
        <sf:input path="empId" type="hidden"/>
        归属项目：
        <sf:select path="workingProject">
            <c:forEach var="p" items="${projectList}">
                <sf:option value="${p.projectId}">${p.projectName}</sf:option>
            </c:forEach>
        </sf:select>
        所在周期：
        <sf:input path="workingTime" type="date" cssStyle="width: 150px" onchange="getWork()"/>
        <span style="color: red">${errors.workingTime}</span>
        周代码行数：
        <input name="workingWeekCodes" <c:if test="${working.workingWeekCodes!=0}">value="${working.workingWeekCodes}" </c:if> type="text" style="width: 100px" size="10" oninput="if (! /^\d+$/ig.test(this.value)){this.value='';}"/><br/>
        <div class="well">
            <table class="table">
                <thead>
                <tr>
                    <th class="vv">阶段</th>
                    <th class="vv">计划（工作量）</th>
                    <th class="vv">实际（工作量）</th>
                </tr>
                </thead>
                <tbody>
                <c:forEach begin="0" end="3" var="i">
                    <tr>
                        <td>
                            <c:if test="${i==0}">需求分析</c:if>
                            <c:if test="${i==1}">设计</c:if>
                            <c:if test="${i==2}">编码</c:if>
                            <c:if test="${i==3}">测试</c:if>
                            <sf:input path="phaseList[${i}].phaseId" type="hidden"/>
                            <sf:input path="phaseList[${i}].phaseName" type="hidden" value="${i+1}"/>
                        </td>
                        <td>
                            <sf:input id="p${i}" path="phaseList[${i}].phasePlan" onblur="getTotal('p','${i}')" style="width: 120px" size="3" oninput="if (! /^\d+$/ig.test(this.value)){this.value='';}"/>小时
                        </td>
                        <td>
                            <sf:input id="a${i}" path="phaseList[${i}].phaseActual" onblur="getTotal('a','${i}')" style="width: 120px" size="3" oninput="if (! /^\d+$/ig.test(this.value)){this.value='';}"/>小时
                        </td>
                    </tr>
                </c:forEach>
                <tr>
                    <td>当前统计</td>
                    <td><span id="plan1"></span></td>
                    <td><span id="actual1"></span></td>
                </tr>
                <tr>
                    <td>工作量统计</td>
                    <td><span id="plan">${planTime}</span></td>
                    <td><span id="actual">${actualTime}</span></td>
                </tr>
                </tbody>
            </table>
            <button class="btn btn-primary" onclick="go()" type="submit" style="margin-left: 40px;margin-top: 30px">提交</button>
            <button type="button" onclick="ToempShowPage()" class="btn btn-primary" style="margin-left: 20px;margin-top: 30px">取消</button>
        </div>
    </sf:form>
</div>
<script type="text/javascript" src="${pageContext.request.contextPath}/dist/backEnd/js/datetime.js"></script>
</body>
</html>
